package com.sunrise.generico.entidade;

import java.util.Collection;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;

import lombok.Getter;
import lombok.Setter;

import org.hibernate.validator.constraints.NotEmpty;

import com.sunrise.generico.entidade.iface.EntidadeManter;

@Entity
@Table(name = "filial")
public class Filial implements EntidadeManter {


	/**
	 * 
	 */
	private static final long serialVersionUID = 503181383594122379L;

	@Id
	@SequenceGenerator(name="pk_sequence",sequenceName="filial_id_seq", allocationSize=1)
	@GeneratedValue(strategy=GenerationType.SEQUENCE,generator="pk_sequence")
	@javax.persistence.Column
	@Getter @Setter
	private Long id;
	
	@NotEmpty( message="{filialObrigatorio}")
	@Column(name = "nome", length = 60, nullable = false, unique = true)
	@Getter @Setter
	private String nome;
	
	@NotNull(message= "{responsavelObrigatorio}")
	@OneToOne
	@Getter @Setter
	private Usuario responsavel;
	
	@ManyToMany(fetch=FetchType.LAZY, cascade = {CascadeType.PERSIST, CascadeType.MERGE })
	@JoinTable(name="filial_usuario", joinColumns={@JoinColumn(name="filial_id", referencedColumnName="id")},
		      inverseJoinColumns={@JoinColumn(name="usuario_id", referencedColumnName="id")})
	@Getter @Setter
	private Collection<Usuario> usuarios;
	
	@OneToOne
	@Getter @Setter
	private Endereco endereco;
	
	@Column(name = "ativo")
	@Getter @Setter
	private Boolean ativo;
	
	@Column(name = "cnpj", length = 18)
	@Getter @Setter
	private String cnpj;
	
	@OneToMany
	@Getter @Setter
	private Collection<Venda> vendas;
	
}
